---
sidebar_class_name: hidden
---

# Summarization

A summarization chain can be used to summarize multiple documents. One way is to input multiple smaller documents, after they have been divided into chunks, and operate over them with a MapReduceDocumentsChain. You can also choose instead for the chain that does summarization to be a StuffDocumentsChain, or a RefineDocumentsChain.

import CodeBlock from "@theme/CodeBlock";
import SummarizeExample from "@examples/chains/summarization_map_reduce.ts";
import SummarizeExampleIntermediateSteps from "@examples/chains/summarization_map_reduce_intermediate_steps.ts";
import SummarizeSeparateOutputLLMsExample from "@examples/chains/summarization_separate_output_llm.ts";

import IntegrationInstallTooltip from "@mdx_components/integration_install_tooltip.mdx";

<IntegrationInstallTooltip></IntegrationInstallTooltip>

```bash npm2yarn
npm install @langchain/anthropic @langchain/openai
```

<CodeBlock language="typescript">{SummarizeExample}</CodeBlock>

## Intermediate Steps

We can also return the intermediate steps for `map_reduce` chains, should we want to inspect them. This is done with the `returnIntermediateSteps` parameter.

<CodeBlock language="typescript">{SummarizeExampleIntermediateSteps}</CodeBlock>

## Streaming

By passing a custom LLM to the internal `map_reduce` chain, we can stream the final output:

<CodeBlock language="typescript">
  {SummarizeSeparateOutputLLMsExample}
</CodeBlock>
